//Copyright (c) Microsoft Corporation.  All rights reserved.

using System;
using System.Collections.Generic;
using System.Text;

namespace Eas.WebCrawler.Interfaces {
    /// <summary>Stores state that is accumulated while processing a request.</summary>
    /// <remarks>Any of the properties of the interface which are reference types can be null.  If you use these properties you should check for null first.</remarks>
    public interface ProcessingState : IDisposable {
        /// <summary>The <see cref="Request"/> being processed.</summary>
        Eas.WebCrawler.Interfaces.Request Request { get; }
        /// <summary>The details of the web request which was used to access the <see cref="Uri"/> of this request.</summary>
        WebRequestInterface WebRequest { get; }
        /// <summary>The details of the response generated while processing this request.</summary>
        WebResponseInterface WebResponse { get; }
        /// <summary>The <see cref="System.IO.Stream"/> containing the contents of the response returned from the web request.</summary>
        System.IO.Stream ResponseStream { get; }
        /// <summary>Whether or not the returned response was text (<code>true</code>) or binary (<code>false</code>).</summary>
        bool IsTextResponse { get; }
        /// <summary>The unique ID of the worker processing request.</summary>
        /// <remarks>All requests are processed by a worker.  Each worker has a unique ID between <code>0</code> and <code>WorkerCount-1</code>.</remarks>
        int Id { get; }
        /// <summary>Whether or not the <see cref="WebCrawlerEngine"/> was paused at some point while this request was being processed.</summary>
        /// <remarks>This property will return <code>true</code> even aftet the <see cref="WebCrawlerEngine"/> has been subsequently unpaused.</remarks>
        bool WasPaused { get; }
        /// <summary>The current <see cref="WorkerState"/> of the worker processing this request.</summary>
        WorkerState WorkerState{get;}
        /// <summary>Requests a change in the working state of the worker processing this request.</summary>
        /// <param name="newState">The new <see cref="WorkerState"/> to which you want the worker to swtich.</param>
        void RequestChange(WorkerState newState);
        /// <summary>Copies change requests from the passed-in state to this one.</summary>
        /// <param name="state">The state from which change requests will be passed.</param>
        void CopyChangeRequests(ProcessingState state);
        /// <summary>The <see cref="TemporaryStorage"/> which holds the stored contents of the response returned from this request.</summary>
        TemporaryStorage ResponseStore { get;}
    }
}
